<?php
declare(strict_types=1);

namespace service\exception;


use think\Exception;

class ServiceException extends Exception
{

    // 登录超时
    const EXCEPTION_LOGIN_OUT_TIME = 1001;

    public function __construct(string $mode,  string $message, $errorRemark = '', int $code = 1000)
    {
        $this->message = $message;
        $this->code = $code;

        $messageConfig = config('error.' .$mode . '.' . $message);
        if(!empty($messageConfig)){
            $this->message = $messageConfig['message'];
            $this->code = $messageConfig['code'];
        }

        $this->setData('error', [
            'code'    => $this->getCode(),
            'message' => $this->getMessage(),
            'data'    => $errorRemark,
        ]);
    }
}